/********************************************
 * SV。Com call banner 控制类js
 * @Function ： 对callbanner的基本通讯、高级功能、组长功能等交互模块进行
 *            模块的逻辑控制
 * @author   : 
 * @create   : 2016-8-1
 * @Companny :  .,Ltd 
 ********************************************/
/****************************************************************************************************
 * 设置按钮的展现样式
 * @Param _disableStyle : hidden 表示不可用按钮就隐藏， disable：不可用则显示禁用的风格
 * @param _iconText     : icon 或 text 表示按钮
 * @param _imgPath      : 图片跟路径
 * @author flyway
 * 特别提示：
 *     icon 方式，
 *        <script type="text/javascript" src="hscc/js/SV-callbanner-ui-flat-3.9.js"></script> 
 *     text 方式
 *        <script type="text/javascript" src="hscc/js/SV-callbanner-ui-text-3.9.js"></script>
 *****************************************************************************************************/
 window.onload = function () {
     if (handlers) {
        handlers.callphone = callphone_58;
        handlers.setStatus = overridSetStatus;
        handlers.getStatus = overridgetStatus;//要文字，还是要数字状态  需确认
    } 
}; 
var g_3rdNo="";
var monedagentno="";
function IsIntegerOnly(e) {
    var keycode = document.all ? e.keyCode : e.which;

    if (keycode == 8 || keycode == 0 || (keycode > 47 && keycode < 58)) {
        return true;
    }
    else {
        return false;
    }
}


 //alert("测试，记得删除 callcenter_config");
 var callcenter_config="0";

function overridgetStatus() {
    return callStateHelper.getText(callStateHelper.getCurCallState());
}

function overridSetStatus(state) {
    switch (state) {
        case "空闲":
        {
            FlashAgentX.SetSeatState(0);
            break;
        }
        case "忙碌":
        {
            FlashAgentX.SetSeatState(1);
            break;
        }
        case "小休":
        {
            FlashAgentX.SetSeatState(2);
            break;
        }
    }
}



function showMessage(msg) {
	console && console.log("操作提示:"+ msg);
	//$.messager.anim('show', 1000);
	//$.messager.show('操作提示', msg);
}

/******************************************
* 主状态输出， 该函数在callengine中会调用，不能删除
*   注意：这里仅显示电话状态，操作提示不要在这里输出
********************************************/
function showMainStatus(msg) {
    var tmpObj = document.getElementById("hs_mainstatus");
    if (tmpObj != null) tmpObj.innerHTML = msg;
}

/******************************************
* 子状态输出， 该函数在callengine中会调用，不能删除
********************************************/
var msgsize = 0;
function showSubStatus(msg) {
    //
    //  var tmpObj = document.getElementById("hs_substatus") ;
    //单独一个日志输出窗口
    msgsize += 1;
    var tmpObj = document.getElementById("log_box");
    if (tmpObj != null) {
        if (msgsize > 200){ tmpObj.innerHTML = "";  msgsize =0 ;}
        tmpObj.innerHTML += "<li>" + msg + "</li>";
    }
    console && console.log("调试信息---------->"+msg);
}


/****************** 
    * 带业务参数呼出
    * 
    */
    function callphone_58(phone, businessdata) {
      businessdata.queue_name =callcenter_config;
        callDataHelper.setBusinessdata58(businessdata);
        if (phone != "请输入电话号码" && phone!="") {
        FlashAgentX.makecall(phone, ''); //呼出        
    }
    else {
        alert("电话号码不能为空");
    }
    console.log('phone' + phone);
}

function onbeforecall_58(phone) {
  
    handlers && handlers.onbeforecall(phone);
}

/*********
    * 来电振铃
    * 
    */
    function onring_58(phone, callid){ //,bussData58) {
    alert("onring_58:phone "+phone+" callid:"+callid );//+" bussData58:"+ bussData58);
    handlers && handlers.onring(phone, callid);
}

/*******
    * 电话成功挂机通知
    * @param startdatetime
    * @param enddatetime
    * @param phone
    * @param timelong
    * @param callid
    * @param direction  true 呼入， false 呼出
    * 
    */
    function on_success_hangup_58(startdatetime, enddatetime, phone, timelong, callid, direction) {
        handlers && handlers.on_success_hangup(startdatetime, enddatetime, phone, timelong, callid, direction);
    }
//电话条非成功挂断时，如需，重写业务逻辑 
function on_fail_hangup_58(startdatetime, enddatetime, phone, timelong, callid, direction) {
    handlers && handlers.on_fail_hangup(startdatetime, enddatetime, phone, timelong, callid, direction);
    console && console.log("tianji on_fail_hangup_58");
}
/************
    * 开始呼出时通知振铃
    */
    function oncalldata_58(startdatetime, extnum, callid) {
        handlers && handlers.oncalldata(startdatetime, extnum, callid);
    }
/*********
    *坐席接通时，或外呼接通时，如需，重写业务逻辑, 由状态解析后获取           
    * @param startdatetime
    * @param extnum
    * @param callid
    * 现在方式 呼出时 talk 状态 即可， 呼入时 系统暂没有区分talk 与 connect，
    */
    function onconnected_58(startdatetime, extnum, callid) {
        handlers && handlers.onconnected(startdatetime, extnum, callid);
    }


//登录成功
function onLogin(extNum) {
    //坐席登录成功，开始注册sip phone
    showSubStatus("onlogin:" + extNum);
    g_AcdInfo.isCheckIn = true;
    //系统登录后会自动示忙，避免人员未就绪立即分配电话进来， 预留 x 秒，自动实现， 具体是否采用由开发人员斟酌
    setTimeout("FlashAgentX.setSeatState(0);", 2000);       
    onCallState && onCallState(1); //处理登录后的界面初始化 
    handlers && handlers.onlogined(extNum);
}

//退出成功
function onLogout() {
    g_AcdInfo.isCheckIn = false;
    showSubStatus("onlogout ");
    handlers && handlers.onlogouted();
}


$(function () {
    console.log('document ui ready');
    /***
     * 上线、下线、应答、拒绝等4合一：
     */
     $("#btn_onoff_line").live("click", function () {
        if (!getButtonEnable(this)) return;
        switch (this.fun_value) {
            case 0: { FlashAgentX.online(); break; }  //坐席分机上线
            case 1: { FlashAgentX.offline(); break; }
        }
    });

  //$("#dialout_input").live("keydown",IsIntegerOnly);

     function stopPropagation(e) {
        if (e.stopPropagation) 
            e.stopPropagation();
        else 
            e.cancelBubble = true;
    }
    /***
     * 58 坐席忙闲控制，有多个子状态，不托管给系统管理按钮状态
     */
     $("#btn_ready_busy").live("click", function (e) {
        if (!getButtonEnable($("#btn_ready_busy"))) {
            $("#divShowStatus").hide();
            stopPropagation(e);
            return;
        }
        $("#divShowStatus").toggle();
        stopPropagation(e);
    });

     $("#btn_readybusy_1").live("click", function () {
        FlashAgentX.setSeatState(this.fun_value);
        $("#divShowStatus").hide();
    });

     $("#btn_readybusy_2").live("click", function () {
        FlashAgentX.setSeatState(this.fun_value);
        $("#divShowStatus").hide();
    });

     

    /***************************
     * 签入 0， 签出1
     **************************/
     $("#btn_login").live("click", function () {
        if (!getButtonEnable(this)) return;
        switch (this.fun_value) {
            case 0: { FlashAgentX.checkin(); break; }
            case 1: { FlashAgentX.checkout(); break; }
        }
    });
    //      
    $("#btn_connect").live("click", function () //此功能要改 
    {

        var res = FlashAgentX.connect();
    });

    /***
     *  保持 0， 恢复 1
     */
     $("#btn_hold_unhold").live("click", function () {
        if (!getButtonEnable(this)) return;
        var res = '0';
        switch (this.fun_value) {
            case 0: { FlashAgentX.holduser(); break; }
            case 1: { FlashAgentX.unholduser(); break; }
        }
    });
    /***
     * 转移IVR前，弹出ivr节点表
     */
     $("#btn_toivr").live("click", function () {
        if (!getButtonEnable(this)) return;
        showivrflow1();
        //转ivr做满意度调查
        //var sToIvr = FlashAgentX.g_callEvent.callid + "," + g_AcdInfo.entId + "," + g_AcdInfo.qId + "," + g_AcdInfo.optId;
        //if(FlashAgentX.g_callEvent !=null)
        // sToIvr = FlashAgentX.g_callEvent.callid + "," + g_AcdInfo.entId + "," + g_AcdInfo.qId + "," + g_AcdInfo.optId;
        
        //FlashAgentX.gotoivr(184, 184, sToIvr);
        //showSubStatus && showSubStatus("FlashAgentX.gotoivr  "+ sToIvr);
    });

     $("#btn_hungup").live("click", function () {
    	 FlashAgentX.dropcall(); 
     });
     
    //呼出、挂机
    $("#btn_callout").live("click", function () {    	
        if (!getButtonEnable(this)) return;
        switch (this.fun_value) {
            case 0: { //呼出前的拨号盘控制
             if( ! getButtonEnable(this)) return ;
             switch(this.fun_value)
             {
				   case 0:{ //呼出前的拨号盘控制
                    var tmpObj = document.getElementById("dialout_input") ;					   
                    if(tmpObj!=null && tmpObj.value !=""){
					//	  alert("测试用，接入crm需 onbeforecall_58  " + tmpObj.value );
                   //   if( onbeforecall_58) onbeforecall_58(tmpObj.value) ; 
                    //  else
                        FlashAgentX.makecall(tmpObj.value,"");
                }
                else					    
                   showSubStatus("请输入电话!");					
               break ; 
           }  
           case 1:{  FlashAgentX.dropcall();  break ;     }  
       }		 			 
       break ;
   }
   case 1: { FlashAgentX.dropcall(); break; }
}
});
    $(".dial_input_box div").live("click", function (event) { event.stopPropagation(); });
    

    /*****************
     * 咨询坐席复合键 咨询准备 + 结束咨询
     * 1. 咨询前准备--获取队列坐席状态表
     * 20160920 58项目，咨询内线、外线合并，采用动态创建输入框实现工号或电话输入
     ******************/
     $("#btn_consult").live("click", function () {
        if (!getButtonEnable(this)) return;
        switch (this.fun_value) {
            case 0: { //动态创建div输入框
                createConsultBox("btn_consult");
                break;
            }
            case 1: { //坐席咨询后的退出
                stopConsultAgc();
                break;
            }   //释放被咨询坐席
            case 2: { //坐席咨询后的退出
                stopConsultOut();
                break;
            }   //释放被咨询坐席
        }
    });

    //转移坐席，0转内，1转外
    $("#btn_transfer").live("click", function (event) {
        if (!getButtonEnable(this)) return;
        switch (this.fun_value) {
            case 0: { //转坐席                      
                FlashAgentX.transseat();
                break;
            }
            case 1: { //坐席咨询后的退出
                FlashAgentX.transcall();
                break;
            }   //释放被咨询坐席                  
        }
    });
    /************************
     * 会议建立与拆除 //btn_confence 0=内三方，1=开始外三，2=结束内三方，3=结束外三    
     */
     $("#btn_confence").live("click", function (event) {
        if (!getButtonEnable(this)) return;
        switch (this.fun_value) {
            case 0:
            case 1:
                { FlashAgentX.inmeet(); break; }  //建立三方
                //退出三方，将用户接回 内，外一样的
                case 2:
                case 3:
                {
                    FlashAgentX.unholduser();
                    break;
                }
            }
        });

     $("#btn_monitor").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         //createMonitorBox("btn_monitor");
         var url1 = "agc_monitor.html";
         window.open(url1,"monitorwin", "height=600, width=800, top=100, left=200, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
     });
     
     $("#btn_monqueue").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         //createMonitorBox("btn_monitor");
         var url1 = "queue_monitor.html";
         window.open(url1,"monquewin", "height=600, width=800, top=100, left=200, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
     });
     
     $("#btn_stop_monitor").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         FlashAgentX.outmoniter(monedagentno);
         //monedagentno监听时赋值
     });
     
     $("#btn_force_join").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         switch (this.fun_value) {
	         case 0: { //开始插话
	             FlashAgentX.insert();
	             break;
	         }
	         case 1: { //结束插话
	             FlashAgentX.outinsert();
	             break;
	         }
	     }
     });
     
     $("#btn_whisper").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         switch (this.fun_value) {
             case 0: { //开始耳语
                 FlashAgentX.whisper();
                 break;
             }
             case 1: { //结束耳语
                 FlashAgentX.outwhisper();
                 break;
             }
         }
     });
     
     $("#btn_tokeover").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         switch (this.fun_value) {
	         case 0: { //拦截
		         FlashAgentX.robcall();
		         break;
		     }
		     case 1: { //挂机
		         FlashAgentX.dropcall();
		         break;
		     }
         }
     });
     
     $("#btn_force_hungup").live("click", function (event) {
         if (!getButtonEnable(this)) return;
         FlashAgentX.stopcall();//
     });

});
 

/*****************************************************
 * 呼入、呼出事件通知振铃，时间可行
 * @param callercalledinfo  ：呼叫随路数据 
 ***********************************************/
 function OnRingTime(_evt)
 {
   try{  
      showSubStatus && showSubStatus("onRingTime  "+ _evt.ringtime+" "+_evt.called);
    
      
      //callDataHelper.parseRingTime(_callData);
      if( _evt.direct == 1 )
      {  
          var bussData58 = {}; 
           bussData58.queue_name =callcenter_config;
          bussData58.call_id = _evt.callid;
          bussData58.call_no = _evt.caller;
          bussData58.called_no = _evt.called;
		  bussData58.call_type = "normal";  //normal普通来电，
          bussData58.agent_id =  g_CtiId  ;
          bussData58.agent_emp_no =  g_AcdInfo.optId  ;
          bussData58.to_number = _evt.caller  ;
          bussData58.ring_time = _evt.ringtime ;
          //mod chenyl0826 
			////cmsHelper.addAgentCall(OnAddedAgentCall,bussData58); 			 
			//发送来电通知
          console&&console.log("执行呼入振铃:::"+ _evt.caller);
          onCallState(12);
			onring_58 && onring_58(_evt.caller,_evt.callid);//,bussData58) ;
            return ;
        }else{
        	
        }
	    } catch(e1)
	    {
	      //showSubStatus && showSubStatus("执行【OnRingTime.1】异常:"+  e1.message);
	    	console&&console.log("执行【OnRingTime.1】异常:"+  e1.message);
	  }
  
	//呼出
  try{  
	      //2。呼出 时，用户session没有建立，没有与用户相关的呼叫记录
     	   	//发送到CMS中保存客户业务数据
            var bussData58 = callDataHelper.getBusinessdata58() ; 
            if(bussData58 == null) bussData58 = new Object() ;
             bussData58.queue_name =callcenter_config;
            bussData58.call_id = _evt.callid ;
            bussData58.call_no = _evt.caller ;
            bussData58.called_no = _evt.called ;
            bussData58.ring_time = _evt.ringtime ;
            bussData58.agent_id =   g_AcdInfo.optId  ;
            bussData58.agent_emp_no =  g_AcdInfo.optId  ;
            bussData58.to_number =  _evt.called ; 
			bussData58.call_type = "dialout";  //normal普通来电，
			//mod chenyl0826 
			////cmsHelper.addAgentCall(OnAddedAgentCall,bussData58);	
			onCallState(12);
           console.log('addAgentCall :'+ _evt.called);		
       } catch(e2)
       {
          showSubStatus && showSubStatus("执行【OnRingTime.2】异常:"+  e2.message);

      }
      oncalldata_58(_evt.ringtime , g_AcdInfo.optId, _evt.callid)  ;	 
  }
  

/*************************************
 * 当坐席呼出流水后端记录成功后事件
 *************************************/
 function OnAddedAgentCall(errcode,errmsg, data) {
    if (errcode != "0") {
        showSubStatus("业务数据添加失败:" + errmsg);
        return;
    }
    callDataHelper.UpdateSendCms();
}

/*************************************
 * 当坐席呼出流水后端记录成功后事件
 *************************************/
 function OnAnswer(_evt) {
   try{ 
    showSubStatus && showSubStatus("onanswer：  " + _evt.anstime + " "+ _evt.called);
    onCallState(3);
    onconnected_58(_evt.anstime, g_AcdInfo.optId, _evt.callid);
	} catch(e)
	{
	   showSubStatus && showSubStatus("执行【OnAnswer】异常:"+  e.message);
	}
}

/*****************************************************
  * 挂机通知
  * @param _direct ：坐席挂机1，客户挂机0
  */
  function OnHungupTime(_evt) {
    try{  
       showSubStatus && showSubStatus("onhungupTime：  " + _evt.endtime);
       onCallState(1); 
       if (_evt.direct == 1)
           on_success_hangup_58 && on_success_hangup_58(_evt.anstime , _evt.endtime, _evt.caller,_evt.talktimelen, _evt.callid, 0);
       else
           on_success_hangup_58 && on_success_hangup_58(_evt.anstime, _evt.endtime, _evt.called, _evt.talktimelen, _evt.callid, 1);
   }
   catch(e)
   {
       showSubStatus && showSubStatus("执行【OnHungupTime】异常:"+  e.message);
   }
  // callDataHelper.restData();
}

function OnAnswer3(_evt) {
	
	showSubStatus && showSubStatus("OnAnswer3：  "+ _evt.anstime3+" "+ _evt.called3);
	var calledno = _evt.called3;
	if(calledno.length>5){  //外线
		onCallState && onCallState(7);
	}else{  //内线
		onCallState && onCallState(6);
	}
  var bussData58 = new Object() ; 
   bussData58.queue_name =callcenter_config;
  bussData58.call_id = _evt.callid3 ;
  bussData58.agent_id =  g_AcdInfo.optId  ;
  bussData58.agent_emp_no =  g_AcdInfo.optId  ;
	bussData58.call_type = "dialtransfer" ;  //咨询
   	//mod 0826 chenyl	
	//cmsHelper.addAgentCall(null,bussData58);	
    }

  
/********************************************************
 * 咨询坐席 
 ******************************/
 function doConsultAgc(toWorkNo) {
    var res = '0';
    g_3rdNo = toWorkNo;
    //增加做席间通话功能
    ///if (callStateHelper.getCurCallState() < callStateHelper.talking) {

    ///    if (toWorkNo != "请输入工号或电话" && toWorkNo != "") {
    ///        res = FlashAgentX.makecall(toWorkNo, ''); //呼出         
    ///    }
    ///    else {
    ///        alert("工号或电话不能为空");
    ///    }
    ///    console.log('toWorkNo' + toWorkNo);
    ///}
    ///else {
    ///    if (toWorkNo != "请输入工号或电话" && toWorkNo != "") {
    ///        res = FlashAgentX.callseatEx(toWorkNo, callDataHelper.getCallData());
    ///    }
    ///    else {
    ///        alert("工号或电话不能为空");
    ///    }
    ///    console.log('toWorkNo' + toWorkNo);
    ///}
    
    res = FlashAgentX.callseat(toWorkNo);
    callDataHelper.isAgc = true;
    callDataHelper.telNo = toWorkNo;

    closeAgcContainer('agc_container_consult');
}
/****************************************************
 * 咨询外线结束
 * @param workno  目标坐席
 **************************************************/
 function stopConsultAgc() {
    var res = FlashAgentX.freeseat();

    if (callDataHelper.getIsCallIn())
        showMainStatus("来电:" + callDataHelper.getCaller());
    else
        showMainStatus("去电:" + callDataHelper.getCalled());
}



//转移到咨询坐席
function doTransAgc() {
    var res = FlashAgentX.transseat(g_3rdNo);
    if (res != '0') showSubStatus(res); else showSubStatus("转咨询成功！");
}


function doTransQueue(qid) {
    var res = FlashAgentX.transqueue(qid, g_CallerCallInfo);
    if (res != '0') showSubStatus(res); else showSubStatus("转队列");
}


/************
 * 恢复
 */
 function doUnHold() {
    var res = FlashAgentX.unholduser();
    //if(res !='0') showSubStatus('unhold失败:'+ res);
}


/****************************************************
 * 咨询外线
 * @param workno  目标坐席
 **************************************************/
 function doConsultOut(telNum) {
    g_3rdNo = telNum;
    var res = FlashAgentX.consult(g_3rdNo, '');
    callDataHelper.isAgc = false;
    callDataHelper.telNo = g_3rdNo;
    /*  if(callDataHelper.getIsCallIn())            
          showMainStatus("来电:"+ callDataHelper.getCaller() +"<br>外线:"+ g_3rdNo);
        else
          showMainStatus("去电:"+ callDataHelper.getCalled() +"<br>外线:"+ g_3rdNo);        */
  }

/****************************************************
 * 咨询外线结束
 * @param workno  目标坐席
 **************************************************/
 function stopConsultOut() {
    var res = FlashAgentX.droptouser();
}




/********************************
 * 关闭agc选择窗口
 * @param divId 窗口的id
 */
 function closeAgcContainer(divId) {
    var tObj = document.getElementById(divId);
    if (tObj != null)
        tObj.style.display = "none";

}

/*****************************
 * 动态创建咨询输入框，可接收工号，电话号码
 * @param id
 */
 function createConsultBox(id) {
    var obj = document.getElementById("_consultDiv");
    if (obj != null) { //如果已经打开在关闭窗口
        $('#_consultDiv').remove();
        return;
    }
    var htmlTxt = "<div id='_consultDiv' onclick='event.stopPropagation() ;'> ";
    htmlTxt += "<div style='background:#0d2ca1; width:300px;'> ";
    htmlTxt += "    <input id='_txt_num' type='text'  onkeypress='return IsIntegerOnly(event);'  value='请输入工号或电话' onclick='onConsultInputClick();' onkeydown='onConsultKeyDown(event.keyCode||event.which); ' style='border: 1px; text-indent: 6px; font-size: 11px; height:22px; outline:block; font-weight: normal; width: 106px;'/> ";
    htmlTxt += "     <input type = 'button'  onclick='doConsult()'  value='咨询'> ";
    htmlTxt += "     <input type = 'button'  onclick= $('#_consultDiv').remove(); value='关闭'> ";
    htmlTxt += "    </div>      ";
    htmlTxt += "</div>   ";
    $("#" + id).append(htmlTxt);
}
 
 function createMonitorBox(id) {
	    var obj = document.getElementById("_consultDiv");
	    if (obj != null) { //如果已经打开在关闭窗口
	        $('#_consultDiv').remove();
	        return;
	    }
	    var htmlTxt = "<div id='_consultDiv' onclick='event.stopPropagation() ;'> ";
	    htmlTxt += "<div style='background:#0d2ca1; width:300px;'> ";
	    htmlTxt += "    <input id='_txt_num' type='text'  onkeypress='return IsIntegerOnly(event);'  value='' style='border: 1px; text-indent: 6px; font-size: 11px; height:22px; outline:block; font-weight: normal; width: 106px;'/> ";
	    htmlTxt += "     <input type = 'button'  onclick='doMonitor()'  value='监控'> ";
	    htmlTxt += "     <input type = 'button'  onclick= $('#_consultDiv').remove(); value='关闭'> ";
	    htmlTxt += "    </div>      ";
	    htmlTxt += "</div>   ";
	    $("#" + id).append(htmlTxt);
	}
//咨询输入框事件
function onConsultInputClick() {
    var obj = document.getElementById("_txt_num");
    if (obj.value == "请输入工号或电话") obj.value = "";
}
//回车自信
function onConsultKeyDown(value) {
    if (value == 13 || value == 32) {
        return doConsult();
    }
}

function doConsult() {
    var obj = document.getElementById("_txt_num");
    if (obj == null) return;
    var _num = obj.value;

    if (_num != "请输入工号或电话" && _num != "") {
        FlashAgentX.consult(_num, "");  // calluser      
    }
    else {
        alert("工号或电话不能为空");
    }
    	//console.log('_num' + _num);
         $('#_consultDiv').remove();
     }

//咨询
function doMonitor() {
    var obj = document.getElementById("_txt_num");
    if (obj == null) return;
    var _num = obj.value;

    if (_num != "请输入座席工号" && _num != "") {
    	if(_num.length >5) {alert("工号输入无效,请重试!");return ;}
		FlashAgentX.monitor(_num);
	}else {
        alert("座席工号不能为空");
    }
     $('#_consultDiv').remove();
}

   

//前端鉴权-注册坐席入口
function DoRegistAgent() {
    showSubStatus("获取坐席登录信息,稍后!");
    onCallState && onCallState(0);
    if(typeof extNoDeferred !='undefined'){
     $.when(extNoDeferred).done(function(){
        cmsHelper.setCmsUrl(_cmsUrl);
        cmsHelper.getEntToken(onGetAgentToken, _entId, _entPwd, _workNo);
    });
 }else{
		   //flash加载完成开始坐席鉴权
           cmsHelper.setCmsUrl(_cmsUrl);
           cmsHelper.getEntToken(onGetAgentToken, _entId, _entPwd, _workNo);
       }
       
   }

/***
* 回调函数：鉴权成功，获取token
* 开始初始化系统参数    
*/
function onGetAgentToken(errcode, errmsg, data) {
    if (errcode != "0") {
        showSubStatus("操作失败:" + errmsg);
        if (errmsg == "工号不存在")
            showSubStatus("当前坐席尚未在中心开通，请与管理员联系");
        return;
    }
    //取应用服务器参数

    /********************************************************************
            * 注册坐席  采用后台鉴权方案
            * @param entId    企业ID 
            * @param tokenId    企业密码
            * @param workNo    坐席工号
            * @param extType   绑定电话类型：0：pstn电话坐席，1：sip，IP坐席
            * @param extNum   坐席分机, 0 :以系统绑定的分机为准，非0 则以此为准，webrtc统一使用内部绑定方式
            * @param isSipPhone 1:使用webrtc phone，0:使用其他IP话机
            * @returns
            ****************************************************************/
    //function registCallBanner (entId,tokenId,workNo,extType,extNum,isSipPhone,cmsUrl)
    if (typeof extNoDeferred != 'undefined') {
        $.when(extNoDeferred).done(function () {
            registCallBanner(data.entid, data.tokenid, _workNo, _extType, 0, _isWebRt, _cmsUrl);
        });
    } else {
        registCallBanner(data.entid, data.tokenid, _workNo, _extType, 0, _isWebRt, _cmsUrl);
    }

}


function start() {
    //showSubStatus && showSubStatus("start:" );
    //setTimeout("DoRegistAgent()", 1000); // 此方法为“前端验证坐席”的注册入口
    onCallState && onCallState(0);
}
setTimeout("start()", 1000);
